package org.imageMaker.io;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class ImageIO {
	
	private BufferedImage bufIm = null;
	
	public BufferedImage getBufIm() {
		return bufIm;
	}


	public void setBufIm(BufferedImage bufIm) {
		this.bufIm = bufIm;
	}


	public ImageIO(String path) throws Exception{
		try {
			bufIm = javax.imageio.ImageIO.read(new File(path));
		} catch (IOException e) {
			
			e.printStackTrace();
			throw e;
		}
	}
	
	public ImageIO(InputStream img) throws Exception{
		try {
			bufIm = javax.imageio.ImageIO.read(img);
		} catch (IOException e) {
			
			e.printStackTrace();
			throw e;
		}
	}
	
	
	public boolean saveImage(String nameFile) throws Exception{
	    File outputfile = new File(nameFile);
	    try {
			return javax.imageio.ImageIO.write(bufIm, "png", outputfile);
		} catch (IOException e) {
			e.printStackTrace();
			throw e;
		}
	}
}
